# author destiny1
# Date: 2023/8/5 21:20
import threading


g_num = 0

def work1(num):
    global g_num
    for i in range(num):
        g_num +=1
    print("---in work1, g_num is %d---"%g_num)

def work2(num):
    global g_num
    for i in range(num):
        g_num +=1
    print("---in work2, g_num is %d---"%g_num)


#+1操作不是原子操作

if __name__ == '__main__':
    t1 = threading.Thread(target=work1,args=(10000000,))
    t2 = threading.Thread(target=work2,args=(1000000000, ))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print("2 个线程对同一个全局变量操作之后的最终结果是:%s" % g_num)
